package com.autohelper.app.tcp.protocol;




import com.autohelper.app.tcp.model.Message;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

public class MessageEncoder extends MessageToByteEncoder<Message> {
    @Override
    protected void encode(ChannelHandlerContext ctx, Message msg, ByteBuf out) throws Exception {
        byte[] content = msg.getContent();
        out.writeInt(Integer.MAX_VALUE);
        out.writeLong(msg.getReqId());
        out.writeShort(msg.getVersion());
        out.writeShort(msg.getCommand());
        out.writeInt(content.length);
        out.writeBytes(content);
    }
}